#region File Description
//-----------------------------------------------------------------------------
// Primitives3DGame.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using XNADota.Graphics;
#endregion

namespace XNADota.Primitive
{
    public enum EPrimitiveType
    {
        Cube,
        Sphere,
        Teapot,
        Torus,
        Bezier,
    }

    public class DebugPrimitiveRenderer
    {
        private static ERenderState _RenderStates;

        public class PrimitiveInfomation
        {
            public PrimitiveInfomation(Vector3 Position, Color Color)
            {
                this._Position = Position;
                this._Color = Color;
            }

            private Vector3 _Position;
            private Color _Color;

            public Vector3 Position
            {
                get { return _Position; }
            }
            public Color Color
            {
                get { return _Color; }
            }
        }

        public static void AddPermanentPrimitive(Vector3 Position, Color Color)
        {
            _PermanentPrimitives.Add(new PrimitiveInfomation(Position, Color));
        }

        public static void AddImmdiatePrimitive(Vector3 Position, Color Color)
        {
            _ImmediatePrimitives.Add(new PrimitiveInfomation(Position, Color));
        }

        private static GraphicsDevice _GraphicsDevice;
        private static List<PrimitiveInfomation> _PermanentPrimitives;
        private static List<PrimitiveInfomation> _ImmediatePrimitives;
        private static CubePrimitive _Primitive;

        public static void Initialize(GraphicsDevice Device)
        {
            _PermanentPrimitives = new List<PrimitiveInfomation>();
            _PermanentPrimitives.Clear();
            _ImmediatePrimitives = new List<PrimitiveInfomation>();
            _ImmediatePrimitives.Clear();
            _GraphicsDevice = Device;
            _Primitive = new CubePrimitive(Device, 10.0f);

            _RenderStates = ERenderState.Solid | ERenderState.Opaque | ERenderState.EnableDepth | ERenderState.CullCounterClockWise;
        }

        public static void Update(GameTime gameTime)
        {
        }

        public static void Draw(Matrix view, Matrix projection)
        {
            RenderStateManager.Instance.SetRenderStates(_RenderStates);

            for (int primitiveIndex = 0; primitiveIndex < _PermanentPrimitives.Count; primitiveIndex++)
            {
                Matrix world = Matrix.CreateTranslation(_PermanentPrimitives[primitiveIndex].Position);
                Color color = _PermanentPrimitives[primitiveIndex].Color;
                _Primitive.Draw(world, view, projection, color);
            }

            for (int primitiveIndex = 0; primitiveIndex < _ImmediatePrimitives.Count; primitiveIndex++)
            {
                Matrix world = Matrix.CreateTranslation(_ImmediatePrimitives[primitiveIndex].Position);
                Color color = _ImmediatePrimitives[primitiveIndex].Color;
                _Primitive.Draw(world, view, projection, color);
            }
            _ImmediatePrimitives.Clear();
        }

    }
}
